﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace WpfApplication2
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }


        private void btn0(object sender, RoutedEventArgs e)
        {
            ThreadStart ths = new ThreadStart(ModifyUI0);
            Thread thread = new Thread(ths);

            thread.Start();
        }

        private void btn2(object sender, RoutedEventArgs e)
        {
            new Thread(() =>

            {

                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal,

                    new Action(() =>

                    {

                        Thread.Sleep(TimeSpan.FromSeconds(2));

                        this.button1.Content = "欢迎你光临WPF的世界,Dispatche 异步方法！！" + DateTime.Now.ToString();

                    }));

            }).Start();

        }

        private void ModifyUI0()
        {
            

            // 模拟一些工作正在进行

            Thread.Sleep(TimeSpan.FromSeconds(2));

            button0.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart)delegate ()

            {

                button0.Content = "欢迎你光临WPF的世界,Dispatche  同步方法 ！！";

            });

             

        }

        private void Window_SourceInitialized(object sender, EventArgs e)
        {
            MessageBox.Show("sorceInit");
        }
    }
}
